<?php

/**
 * This is the model class for table "medco.patientaddress".
 *
 * The followings are the available columns in table 'medco.patientaddress':
 * @property integer $patientAddressId
 * @property integer $patientId
 * @property integer $addressId
 * @property string $effectiveFrom
 * @property string $effectiveTo
 * @property string $createdBy
 * @property string $createdTime
 * @property string $updatedBy
 * @property string $updatedTime
 *
 * The followings are the available model relations:
 * @property Patients $patient
 * @property Addresses $address
 */
class Patientaddress extends MedcoCActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Patientaddress the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'medco.patientaddress';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('patientId, addressId, effectiveFrom, effectiveTo', 'required'),
			array('patientId, addressId', 'numerical', 'integerOnly'=>true),
			array('createdBy, updatedBy', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('patientAddressId, patientId, addressId, effectiveFrom, effectiveTo, createdBy, createdTime, updatedBy, updatedTime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'patient' => array(self::BELONGS_TO, 'Patients', 'patientId'),
			'address' => array(self::BELONGS_TO, 'Addresses', 'addressId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'patientAddressId' => 'Patient Address',
			'patientId' => 'Patient',
			'addressId' => 'Address',
			'effectiveFrom' => 'Effective From',
			'effectiveTo' => 'Effective To',
			'createdBy' => 'Created By',
			'createdTime' => 'Created Time',
			'updatedBy' => 'Updated By',
			'updatedTime' => 'Updated Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('patientAddressId',$this->patientAddressId);
		$criteria->compare('patientId',$this->patientId);
		$criteria->compare('addressId',$this->addressId);
		$criteria->compare('effectiveFrom',$this->effectiveFrom,true);
		$criteria->compare('effectiveTo',$this->effectiveTo,true);
		$criteria->compare('createdBy',$this->createdBy,true);
		$criteria->compare('createdTime',$this->createdTime,true);
		$criteria->compare('updatedBy',$this->updatedBy,true);
		$criteria->compare('updatedTime',$this->updatedTime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}